package com.cmbchina.service;

import com.cmbchina.entity.Currency;
import com.cmbchina.entity.ExchangeRate;

/**
 * 汇率转换适配器
 */
public class ExchangeRateAdapter{

    private IExchangeRateService exchangeRateService;

    public ExchangeRateAdapter(IExchangeRateService exchangeRateService) {
        this.exchangeRateService = exchangeRateService;
    }

    public ExchangeRate getRate(Currency from, Currency to) {
        if(exchangeRateService instanceof ExchangeRateService){
            return ((SinaExchangeRateService)exchangeRateService).getRate(from, to);
        }else if(exchangeRateService instanceof  SohuExchangeRateService){
            return ((SohuExchangeRateService)exchangeRateService).getSohuRate(from, to);
        }else{
            throw new IllegalArgumentException("not support ExchangeRate type");
        }
    }

}
